<template>
	<div id="app">
		<!-- 		<div v-for="(item, index) in imgList" :key="item">
			<el-image style="width: 100px; height: 100px" :src="require('@/assets/images/'+'test.png')" :preview-src-list="[require('@/assets/images/'+'test.png')]">
			</el-image>
		</div> -->
		<div style="height: 20px;display:flex;align-items: center;">
			<span style="height: 20px;line-height: 20px;font-size: 20px;margin-bottom: 20px;">查看新的留言</span>
		</div>
		<template>

			<el-table :data="tableData" border style="width: 100%">
				<el-table-column fixed prop="leaveMessageId" label="留言ID" width="180">
				</el-table-column>
				<el-table-column prop="userName" label="留言者名称" width="180">
				</el-table-column>
				<el-table-column prop="lmText" label="留言信息">
				</el-table-column>
				<el-table-column prop="lmTime" label="留言时间"> 
				<template slot-scope="scope">
					<div>
						<div>{{ scope.row.lmTime | formatDate }}</div>
					</div>
				</template>
				</el-table-column>
				<el-table-column label="操作">
					<template slot-scope="scope">
						<el-button size="mini" type="primary"
							@click.prevent="handleEdit(scope.$index, scope.row)">回复</el-button>
						<!-- @click.prevent="drawer = true">回复</el-button> -->
					</template>
				</el-table-column>
			</el-table>
			<el-drawer title="留言回复" :visible.sync="drawer" :direction="direction" :before-close="handleClose">
				<el-input type="textarea" placeholder="请输入回复内容" :autosize="{ minRows: 2, maxRows: 6}"
					v-model="reply.lmReply" show-word-limit>
				</el-input>
				<el-button type="primary" plain @click="toReply">回复</el-button>
			</el-drawer>
		</template>
	</div>
</template>

<script>
	import request from '../../utils/axios/request'
	export default {
		inject:['reload'],
		data() {
			return {
				drawer: false,
				direction: 'rtl',
				token: '',
				reply: {
					staffId: '123',
					lmReply: ''
				},
				tableData: [{
					leaveMessageId: '',
					userName: '',
					lmText: '',
					lmTime: '',
				}]
			}
		},
		methods: {
			handleEdit(index, row) {
				this.drawer = true
				console.log(index, row);
				sessionStorage.setItem('LMId', row.leaveMessageId)

			},
			handleClose(done) {
				this.$confirm('确认关闭？')
					.then(_ => {
						done();
						this.reload()
					})
					.catch(_ => {});
			},
			toReply() {
				let lmId = sessionStorage.getItem('LMId')
				request({
					method: 'put',
					url: '/leaveMessage/' + lmId,
					data: this.reply

				}).then((res) => {
					if (res.data.code==100) {
						alert("回复成功")
					}
				})
			}

		},
		created() {
			request({
				method: 'get',
				url: '/leaveMessage/newLeaveMessage'
			}).then((res) => {
				// console.log(res)
				this.tableData = res.data.data
				// console.log(this.tableData)
			})
		}
	}
</script>

<style scoped>
</style>